#ifndef NETWORKBASE_H
#define NETWORKBASE_H

#include "NetworkMessage.h"

class Address
{
private:
	unsigned int address;
	unsigned short port;

public:
	Address();
	Address(unsigned char _a, unsigned char _b, unsigned char _c, unsigned char _d, unsigned short _port);
	Address(unsigned int _address, unsigned short _port);

	void SetAddress(unsigned char _a, unsigned char _b, unsigned char _c, unsigned char _d, unsigned short _port);
	
	unsigned int GetAddress() const {return address;}
	unsigned char GetA() const		{return (unsigned char)(address >> 24);}
	unsigned char GetB() const		{return (unsigned char)(address >> 16);}
	unsigned char GetC() const		{return (unsigned char)(address >> 8);}
	unsigned char GetD() const		{return (unsigned char)(address);}
	unsigned short GetPort() const	{return port;}
	
	bool operator==(const Address &_rhs) const;
	bool operator!=(const Address &_rhs) const;
};	// Address


class Socket
{
private:
	int socket;

public:
	Socket();	
	~Socket();
	
	bool OpenClient(const Address& address);
	bool OpenServer(unsigned short port);
	void Close();
	bool IsOpen() const;	
	bool Send(const Address & destination, const void * data, int size);
	int Receive(Address & sender, void * data, int size);
	bool SetBroadcast();
};	// Socket

bool InitializeSockets();
void ShutdownSockets();

#endif